package com.bytezreo.objectclass;
/**
 * 
 * @Description   重写equals
 * @author  Bytezero·zhenglei!      Email:420498246@qq.com
 * @version
 * @date 2021年9月24日下午1:03:12
 * @
 *
 */


public class OrderEquals 
{
	public static void main(String[] args) {
		
		OrderTwo order1 = new OrderTwo(1001,"Tom");
		OrderTwo order2 = new OrderTwo(1001,"Tom");
		
		OrderTwo order3 = new OrderTwo(1001,"jon");
		
		boolean isEquals = order1.equals(order2);
		System.out.println("order1 与 order2 是否相等："+isEquals);
		
		boolean isEquals2 = order1.equals(order3);
		System.out.println("order1 与 order3 是否相等："+isEquals2);
	}
}


class OrderTwo
{
	private int orderId;
	private String orderName;
	
	
	
	public int getOrderId() 
	{
		return orderId;
	}
	public void setOrderId(int orderId)
	{
		this.orderId = orderId;
	}
	public String getOrderName()
    {
		return orderName;
	}
	public void setOrderName(String orderName)
	{
		this.orderName = orderName;
	}
	
    public OrderTwo(int orderId,String orderName)
    {
    	super();
    	this.orderId = orderId;
    	this.orderName =orderName;
    }

	@Override
	public boolean equals(Object obj) 
	{
		if(this == obj)
		{
			return true;
		}
		if(obj instanceof OrderTwo)
		{
			OrderTwo order =(OrderTwo)obj;
			
			return this.orderId == order.orderId && 
					this.orderName.equals(order.orderName);
			
		}
		
		return false;
		
    }
	
	
}







































